//
//  PosterCollectionView.m
//  HWSGW
//
//  Created by avachen on 15/11/7.
//  Copyright © 2015年 luxuanrui. All rights reserved.
//

#import "PosterCollectionView.h"
#import "PosterCell.h"
#import "UIViewExt.h"
#import "MovieDetailView.h"


@implementation PosterCollectionView
{
    NSString *identify;
}
- (instancetype)initWithFrame:(CGRect)frame
{
        self = [super initWithFrame:frame];
    if (self) {
        
//        self.pagingEnabled = YES;
        
        
        identify = @"PosterCell";
        [self registerClass:[PosterCell class] forCellWithReuseIdentifier:identify];
        
        
    }
    return self;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PosterCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identify forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    cell.movie = self.data[indexPath.item];
    return cell;
    
}
//点击翻转
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    //[单元格对象 翻转]
    if (self.currentItem == indexPath.item) {
        
        PosterCell *pCell = (PosterCell *)[collectionView cellForItemAtIndexPath:indexPath];
        [pCell flipCell];
        
    }else{
        
        [UIView animateWithDuration:0.4 delay:0.0 options:0 animations:^{
            [collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
        } completion:^(BOOL finished) {
//            NSLog(@"compeleted");
        }];
        self.currentItem = indexPath.item;
        
    }
    
    
}

@end
